home *** CD-ROM | disk | FTP | other *** search
- //=============================================================================
- // ScoreKeeper.
- //=============================================================================
- class ScoreKeeper extends Actor placeable;
-
- struct CodeStatus{
- var string Letter;
- var bool Found;
- var int Times;
- };
- const CODELENGTH = 8;
- const LOWASCII = 97;
- const HIGHASCII = 122;
- const NUMOFTRIES = 50;
- var CodeStatus GoalsMet[CODELENGTH];
- var string CodeForSearch;
- var string FirstMessage;
- var string Report;
- var string PMessage;
-
- /*
- function int Main(string Args)
- {
-
- log("*************");
- log("Ch25_O3LIST");
- log("*************");
- //This goes in PostBeginPlay()
- MakeCode();
-
- //This goes in MakeMessage for DOWN
- RunCodeFinder();
- PMessage = ReportFirstMessage();
- Log(PMessage);
-
- return 0;
- }
- */
-
- //========= Interface of Code Class ================
- function public RunCodeFinder(){
- SetGoals();
- DetectLetter();
- }
-
-
- function public string ReportFirstMessage(){
- return CodeForSearch @ FirstMessage @ Report;
- }
-
- function public MakeCode(){
- local int Ctr;
- while (Ctr < CODELENGTH){
- CodeForSearch $= Chr(GenerateRandom());
- Ctr++;
- }
- }
-
- //===================================================
-
- function private string ShowCode(){
- return CodeForSearch;
- }
-
- function private int GenerateRandom(){
- local float High, Low;
- Low = LOWASCII;
- High = HIGHASCII;
- return Int(RandRange(Low, High));
- }
-
- function private SetGoals(){
- local int Ctr;
- Ctr = 0;
- while(Ctr < CODELENGTH){
- GoalsMet[Ctr].Letter
- = Right( Left(CodeForSearch, Ctr+1), 1);
- GoalsMet[Ctr].Found = false;
- Ctr++;
- }
- }
-
- function private GetGoals(){
- local int Ctr;
- Report="";
- while(Ctr < CODELENGTH){
- //----
- Report $= GoalsMet[Ctr].Letter $ GoalsMet[Ctr].Found
- $ GoalsMet[Ctr].Times;
- Ctr++;
- }
- }
-
- function private DetectLetter(){
- local int Ctr, Itr, NumberOfFinds;
-
- Ctr =0;
- while(Ctr < NUMOFTRIES){
- Itr = 0;
- while(Itr < CODELENGTH){
- if( GoalsMet[Itr].Letter == Chr(GenerateRandom() ) ){
- GoalsMet[Itr].Found = true;
- GoalsMet[Itr].Times++;
- NumberOfFinds++;
- }//end if
- Itr++;
- }//end inner while
- Ctr++;
- }//end outer while
- GetGoals();
- CheckForWin();
- }//end Detect
-
- function private CheckForWin(){
- local int Itr, Goal;
- Itr = 0;
- Goal = 0;
- while(Itr < CODELENGTH){
- if(GoalsMet[Itr].Found == true){
- Goal++;
- if(Goal == CODELENGTH){
- FirstMessage = "You found the whole code!";
- }else{
- FirstMessage = "Code is still incomplete!";
- }//end inner if else
- }//end outer if
- Itr++;
- }//end while
- }//end Check
-
- defaultproperties
- {
- }
-